package study01;

public class Java12_object_function {
    public static void main(String[] args) {
        Father f = new Father();
        Children c = new Children();
        f.test("Father"); // FatherFather
        c.test(); // FatherChildren

        AAAA a = new AAAA();
        BBBB b = new BBBB();
        System.out.println(a.sum());
        System.out.println(b.sum()); // 走到父类的sum了，属性在哪里声明就在那里使用
    }
}

class Father {
    void test( String t ) {
        System.out.println("Father" + t);
    }
}

class Children extends Father {
    void test() {
        super.test("Children");
//        System.out.println("Children");
    }
}

class AAAA {
    int i = 10;
    int sum() {
//        return i + 10;
        return getI() + 10; // 使用 getI 方法的话，哪个对象被实例就使用哪个对象的 getI
    }
    int getI() {
        return this.i;
    }
}

class BBBB extends AAAA {
    int i = 20;
//    int sum() {
//        return i + 20;
//    }
    int getI() {
        return this.i;
    }
}
